using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using TitanX;
using static PlayerWaitBox;
/// <summary>
/// 锁定矿
/// </summary>
public class LockingManger : SingletonGetMono<LockingManger>
{

        public bool isAtt;
         public  Tweener tweener;
        public GameObject tipGm;

        public GameObject preBox;
    // Start is called before the first frame update
    void Start()
    {
       //在自身的大小上加上0.2倍
        Vector3 effectScale = transform.localScale + new Vector3(0.1f, 0.1f, 0.2f);
        //设置动画
        Tweener tweener = transform.DOScale(effectScale, 0.6f);
        //设置动画loop属性
        tweener.SetLoops(-1, LoopType.Yoyo);
        tweener.Play();
        //隐藏，立即去执行player的Att方法


        isAtt=false;
    }

    // Update is called once per frame
    void Update()
    {
       
            if(isAtt){
                 
                if(tweener!=null){
                float twRate = tweener.ElapsedDirectionalPercentage();
                isAtt = false;
                                                
                if(0.7f<=twRate&& twRate<=0.9f){    
                    //完美击打，暴击
                    //伤害+N 血量缓存条 
                    Debug.Log("实现了一次暴击");
                }else{
                        Debug.Log("普通攻击");
                }
                 preBox.GetComponent<PlayerWaitBox>().ExecuteCommand();
                tweener.Kill();

                Hide();
                
                }


            }


    }

    public void MovePosition(Vector2 v2) {
        gameObject.SetActive(true);
        gameObject.transform.position = v2;
    }

    //重载个方法，加一个很小的效果
    public void MovePosition(Vector2 v2,BoxType boxType) {

        if(boxType== BoxType.emeny){
            ShowTip();
        }

        gameObject.SetActive(true);
        gameObject.transform.position = v2;
    }

    //一个动画器，为true
    private void ShowTip(){
     tipGm.SetActive(true);

    }



    private void HideTip(){
        tipGm.SetActive(false);
    }



    public void Hide() {
        gameObject.SetActive(false);
        if(tipGm.activeSelf){
            HideTip();
        }

    }


    
    //攻击锁定状态
    public void AttLocking(GameObject preBoxTemp){
        this.preBox=preBoxTemp;

        Player.Instance.weaponGM.SetActive(true);
        GameManger.Instance.handleStart = GameManger.HandleStart.attExcute;

        
        //锁定当前攻击的敌人
        //进行放大缩小，出现一个
        
    //在自身的大小上加上0.2倍
        Vector3 effectScale = transform.localScale + new Vector3(0.85f, 0.85f, 0);
        //设置动画
         tweener = transform.DOScale(effectScale, 0.8f).SetEase(RandomEase());
        //设置动画loop属性
        tweener.SetLoops(-1, LoopType.Yoyo);
        tweener.Play();

        
        //设置 缓动动画
     //    tweener = transform.DOScale(effectScale, 1.2f);
                        //      transform.DOScale(effectScale, 1.2f).SetEase(Ease.OutExpo);

    }




    public Ease RandomEase() {



        Ease[] eases = new Ease[] { Ease.InOutBack ,Ease.InElastic,Ease.InExpo,Ease.InOutExpo,Ease.OutQuint,Ease.InBack,Ease.InBounce,Ease.InCirc};


       return eases[Random.Range(0, 8)];

    }



}
